import utime
from neopixel import NeoPixel
from machine import Pin
from 驱动.ws2812Screen import WS2812Screen
from setting import *
from ImgData import *
 
import random

SCREEN_WIDTH = 32  # 屏幕宽
SCREEN_HEIGHT = 8  # 屏幕高

num_leds = SCREEN_WIDTH * SCREEN_HEIGHT  # 像素数量(led灯珠数量)

np = NeoPixel(Pin(LED_PIN, Pin.OUT), num_leds)  # 创建像素序列对象

screen = WS2812Screen(np, SCREEN_WIDTH, SCREEN_HEIGHT)  # 创建屏幕对象

def create_M(x, y, color, bright): 
    screen.draw_pixel(x,   y,    color, bright)
    screen.draw_pixel(x,   y+1,  color, bright)
    screen.draw_pixel(x,   y+2,  color, bright)
    screen.draw_pixel(x,   y+3,  color, bright)
    screen.draw_pixel(x,   y+4,  color, bright)
    screen.draw_pixel(x+1, y+1,  color, bright)
    screen.draw_pixel(x+2, y+2,  color, bright)
    screen.draw_pixel(x+2, y+3,  color, bright)
    screen.draw_pixel(x+3, y+1,  color, bright)
    screen.draw_pixel(x+4,   y,    color, bright)
    screen.draw_pixel(x+4,   y+1,  color, bright)
    screen.draw_pixel(x+4,   y+2,  color, bright)
    screen.draw_pixel(x+4,   y+3,  color, bright)
    screen.draw_pixel(x+4,   y+4,  color, bright)

def create_X(x, y, color, bright): 
    screen.draw_pixel(x,   y,      color, bright)
    screen.draw_pixel(x,   y+1,    color, bright)
    screen.draw_pixel(x,   y+3,    color, bright)
    screen.draw_pixel(x,   y+4,    color, bright)
    
    screen.draw_pixel(x+1,   y+2,    color, bright)
    screen.draw_pixel(x+2,   y+2,    color, bright)

    screen.draw_pixel(x+3,   y,      color, bright)
    screen.draw_pixel(x+3,   y+1,    color, bright)
    screen.draw_pixel(x+3,   y+3,    color, bright)
    screen.draw_pixel(x+3,   y+4,    color, bright)

def create_Dot(x, y,color, bright): 
    screen.draw_pixel(x,   y,      color, bright)
    screen.draw_pixel(x,   y+1,    (color[0],color[1]+5,color[2]+10), bright)
    screen.draw_pixel(x+1, y+1,    (color[0],color[1]+10,color[2]+20), bright)
    screen.draw_pixel(x+1, y,      (color[0],color[1]+15,color[2]+30), bright)


def create_version1(x, y,color, bright): 
    screen.draw_pixel(x,   y,      color, bright)
    screen.draw_pixel(x+1, y+1,    color, bright)
    screen.draw_pixel(x+2, y,      color, bright)
    screen.draw_pixel(x+4, y+1,    color, bright)
    



# 清屏
np.fill((0,0,0))
np.write()
col1=(random.randint(20,200),random.randint(20,200),random.randint(20,200))
col2=(random.randint(20,200),random.randint(20,200),random.randint(20,200))
col3=(random.randint(20,200),random.randint(20,200),random.randint(20,200))
col4=(random.randint(20,200),random.randint(20,200),random.randint(20,200))



 
while 1:
    create_M(5,2,col1,0.5)
  
        
    create_Dot(11,6,col2,0.5)
    create_X(14,1,col3,0.5)
    create_version1(22,6,col4,0.5)
    screen.show()
    utime.sleep(0.1)
    np.fill((0,0,0))
    col2=(col2[0],col2[1]+15,col2[2]+30)